%==========================================================================
%  Replication program for:
%  Artemov, Georgy, Yeon-Koo Che, and YingHua He
%  "Stable Matching with Mistaken Agents"
%  Journal of Political Economy Microeconomics
%  31 August 2022
%  Main file, calling
%           p0_add_paths.m
%           p1_data_simulation.m
%           p2_summary.m
%           p3_estimation_MC.m
%           p4_rank_reversal.m
%           p5_plot_est.m
%           p6_counterfactuals.m
%==========================================================================
clear, home
fprintf('Programs started at:  %s\n', datestr(datetime('now')))

% start a parallel pool of workers using the default profile
parpool 

%% add relevant paths: programs, tables, figures
% estimated time: < 1 second
run p0_paths.m

%% simulate data
% estimated time: 5 minutes 

disp('--------- Simulating data: started ---------')
run p1_data_simulation.m;
disp('--------- Simulating data: completed ---------')

%% summary stats
% estimated time: 15 seconds 

disp('--------- Summary stats: started ---------')
run p2_summary;
disp('--------- Summary stats: completed ---------')

%% estimation
% estimated time: 25 minutes 

disp('--------- Estimation: started ---------')
run p3_estimation;
disp('--------- Estimation: completed ---------')

%% reversal of the order of expected quality
% estimated time: < 1 second

disp('------------ Rank Reversal: Started   ------------')
run p4_rank_reversal.m;
disp('------------ Rank Reversal: Completed ------------')

%% plot estimates 
% estimated time: 5 seconds 

disp('------------ Plotting: Started   ------------')
run p5_plot_est.m;
disp('------------ Plotting: Completed ------------')

%% counterfactural
% estimated time: 5 minutes 

disp('------------ Counterfactual: Started   ------------')
run p6_counterfactuals.m;
disp('------------ Counterfactual: Completed ------------')
%% finish line
fprintf('Programs finished at:  %s\n', datestr(datetime('now')))
